//
//  TBRMineVipMemberRightCell.m
//  TBRentClient
//
//  Created by tonbright on 2018/5/24.
//  Copyright © 2018年 tonbright. All rights reserved.
//
#define kPictureMargin 0
#import "TBRMineVipMemberRightCell.h"
#import "TBRMemberRightCollectionCell.h"
@interface TBRMineVipMemberRightCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;
@property (weak, nonatomic) IBOutlet UIPageControl *pageController;

@end
@implementation TBRMineVipMemberRightCell
- (void)awakeFromNib {
    [super awakeFromNib];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    //设置layout
    _flowLayout.itemSize = CGSizeMake(Width-20, 135);
    _flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _flowLayout.minimumLineSpacing = 0;
    _flowLayout.minimumInteritemSpacing = 0;
    _flowLayout.sectionInset = UIEdgeInsetsMake(kPictureMargin, kPictureMargin, kPictureMargin, kPictureMargin);
    self.collectionView.backgroundColor = [UIColor colorWithHex:0xe6e6e6];
    //注册nib
    [self.collectionView registerNib:[UINib nibWithNibName:@"TBRMemberRightCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"TBRMemberRightCollectionCellId"];
    [_pageController setValue:[UIImage imageNamed:@"fengexian"] forKeyPath:@"pageImage"];
    [_pageController setValue:[UIImage imageNamed:@"fengexian_select"] forKeyPath:@"currentPageImage"];
    _pageController.currentPage = 0;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TBRMemberRightCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TBRMemberRightCollectionCellId" forIndexPath:indexPath];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    //    if ([self.delegate respondsToSelector:@selector(enumModuleCellClick:)]) {
    //        [self.delegate enumModuleCellClick:indexPath.row];
    //    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == _collectionView) {
        NSInteger page = scrollView.contentOffset.x/scrollView.frame.size.width;
        if (scrollView.contentOffset.x == 0) {
            page = 0;
        }
        self.pageController.currentPage = page;
    }
}

@end
